package process;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;

import dao.BookDao;
import dao.Impl.BookDaoImpl;
import pojo.Book;

public class AddToDB {
	private BookDao bookDao;
	
	public AddToDB(){
		bookDao=new BookDaoImpl();
	}
	
	public void addToDb() throws IOException, ClassNotFoundException{
		ObjectInputStream objIn = new ObjectInputStream(new FileInputStream("BookList.txt"));
		
		long start = System.currentTimeMillis();
		for(int i=1; i<=10; i++){
			Book[] books = new Book[1000];
			for(int j=1;j<=1000;j++){
				Book book = (Book)objIn.readObject();
				books[j-1] = book;
			}
			((BookDaoImpl) bookDao).addBook2(books);
		}
		
		objIn.close();
		long end = System.currentTimeMillis();
		System.out.println(end-start);
	}
	public static void main(String[] args) throws ClassNotFoundException, IOException {
		new AddToDB().addToDb();
	}

}
